#include <iostream>
#include <unistd.h>
#include <cstring>
#include "common.hpp"
int main()
{
    // 将标准输入设置为非阻塞状态
    SetNoBlock(0);
    char buffer[1024];
    while (true)
    {
        int n = read(0, buffer, sizeof(buffer) - 1);
        if (n > 0)
        {
            buffer[n] = 0;
            std::cout << "Echo#" << buffer << std::endl;
            sleep(1);
        }
        // 此时无论是读取失败还是底层IO尚未就绪read返回值都为-1
        // 这里可以使用errno来进行判断
        else
        {
            if (errno == EWOULDBLOCK || errno == EAGAIN)
                std::cout << "底层IO尚未就绪" << std::endl;
            else
                std::cout << "read false, n: " << n << std::endl;
            sleep(1);
        }
    }
    return 0;
}